package dao;

import hibernate.HibernateUtil;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import entity.EmpleadoEntity;

public class EmpleadoDAO {
	protected static SessionFactory sf = null;
	protected static Session session = null;
	static  {
			sf = HibernateUtil.getSessionFactory();
	}

	protected Session getSession(){
		if(session == null || !session.isOpen()){
			session = sf.openSession();
		}
		return session;
	}
	
	public void closeSession(){
		if (session.isOpen()) session.close();
	}
	
	public void grabarEmpleado(EmpleadoEntity empleado){
		Session session = getSession();
		session.beginTransaction();
		session.persist(empleado);
		session.getTransaction().commit();
	}
}
